import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;


public class DoctorDatos {

	public static Doctor getOne(int id)
	{
		Doctor oDoctor = new Doctor();
		
		return oDoctor;
		
	}
	
	public static Doctores getAll()
	{
		Doctores oDoctores = new Doctores();
		
		try {
            Connection con = DriverManager.getConnection("jdbc:h2:~/clinica");
            
            PreparedStatement stmt = con.prepareStatement("SELECT * FROM doctores");
          
            ResultSet rs = stmt.executeQuery();
            while (rs.next()) {
            	Doctor oDoctor = new Doctor();
            	
            	oDoctor.setApellido(rs.getString("apellido"));
            	oDoctor.setNombre(rs.getString("apellido"));
            	oDoctor.setDni(Integer.parseInt(rs.getString("dni")));
            	oDoctor.setEspecializacion(rs.getString("especializacion"));
            	
            	oDoctores.add(oDoctor);
            	
                            }            
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
		
		return oDoctores;
		
	}
	
	public static void addDoctor(Doctor oDoctor)
	{
		try {
            Connection con = DriverManager.getConnection("jdbc:h2:~/clinica");
            
            PreparedStatement stmt = con.prepareStatement(
                    "INSERT INTO doctores VALUES(?, ?, ?, ?);");
            stmt.setString(1, oDoctor.getNombre());
            stmt.setString(2, oDoctor.getApellido());
            stmt.setString(3, String.valueOf(oDoctor.getDni()));
            stmt.setString(4, oDoctor.getEspecializacion());
            
            int res = stmt.executeUpdate();
            
            System.out.println("Insertar doctor: " + res);
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
	}
	
}
